package com.atwisdom.star.service.quality.impl;

import com.alibaba.fastjson.JSONObject;
import com.atwisdom.star.common.util.JsonUtil;
import com.atwisdom.star.common.vo.JsonResult;
import com.atwisdom.star.common.vo.ResultInfo;
import com.atwisdom.star.core.dsl.modelClass.logic.Impl.LogicInstanceDslServiceImpl;
import com.atwisdom.star.exception.pojo.BusinessException;
import com.atwisdom.star.service.business.Routing;
import com.atwisdom.star.service.business.WorkCenter;
import com.atwisdom.star.service.quality.QualityInspectionService;
import com.atwisdom.star.service.util.LogicUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

/**
 * @ClassName: QualityInspectionImpl
 * @ Description: 质检相关定制化处理
 * @author: 王红艳
 * @date:2024/05/15 13:47
 */
@Service
public class QualityInspectionServiceImpl implements QualityInspectionService {

    @Autowired
    private LogicInstanceDslServiceImpl logicInstanceDslServiceImpl;

    @Autowired
    private LogicUtil logicUtil;

    private final String CLASS_NAME = "MateriaQuality";
    private final String TYPE = "logic";

    /**
     * 根据物料查询物料容器存在则查询返回，不存在则新增返回
     * @param data 物料数据
     * @throws BusinessException
     */
    @Override
    @Transactional
    public ResultInfo<?> queryMaterialTemById(JSONObject data)  throws BusinessException {
        int id = data.getIntValue("id");
        if(null==data.get("id")){
            return JsonResult.error(500,"id不能为空");
        }
        JSONObject values = JsonUtil.buildJson(new Object[] {"if_material",id,"sf_name",data.getString("sf_name"),"sf_code",data.getString("sf_code"),"bf_template",true});
        return JsonResult.success(logicUtil.queryUpdateOrAdd(CLASS_NAME,TYPE,values,"if_material","bf_template"));
    }


}
